import GraphFactory from '../graph/graphfactory.js'
import lgxcom from '../common/common.js'
import GlobalConst from '../common/globalConst.js'
var global = GlobalConst.GlobalConst;

import utilfuncs from '../common/tools/utilfuncs.js';
var funcs = utilfuncs.UtilFuncs;

import { CoordTRFUtil } from '../common/tools/coordtool.js'
import { LGXEnums } from '../common/sysenum.js';
import { GlobalVar } from '../common/globalvar.js';


import absgraph from '../graph/absgraph.js';

class Layer {
    constructor(name) {
        this.layerID = 0;
        this.visible = true;
        this.lock = false;
        this.disMaxScaling = 1000;
        this.disMinScaling = 0.1;
        this.name = name;
        this.m_tGraphLst = new Array();
        this.m_defaultLineDefInfo = new lgxcom.LGXLineDefInfo();
    }

    toJson() {
        let obj = {};
        obj["id"] = this.layerID;
        obj["name"] = this.name;
        obj["lock"] = this.lock;
        obj["max"] = this.disMaxScaling;
        obj["min"] = this.disMinScaling;
        obj["lineinfo"] = this.m_defaultLineDefInfo.toJson();
        return obj;
    }
    assignInfo(obj) {
        this.layerID = obj["id"];
        this.name = obj["name"];
        this.lock = obj["lock"];
        this.disMaxScaling = obj["max"];
        this.disMinScaling = obj["min"];
        let lineObj = obj["lineinfo"];
        this.m_defaultLineDefInfo.fromJson(lineObj);
    }

    setVisible(v) { this.visible = v; }
    getVisible() { return this.visible; }

    setLock(v) { this.lock = v; }
    getLock() { return this.lock; }

    getName() { return this.name; }

    setLineColor(v) {

    }

    getLineColor() {
        return this.m_defaultLineDefInfo.color.toHexString();
    }

    setLineWidth(v) {
        this.m_defaultLineDefInfo.lineWidth = v;
    }

    getLineWidth() {
        return this.m_defaultLineDefInfo.lineWidth;
    }

    setLineMode(v) {
        this.m_defaultLineDefInfo.linemode = v;
    }

    getLineMode() {
        return this.m_defaultLineDefInfo.linemode;
    }

    addGraph(graph) {
        if (graph && this.m_tGraphLst.indexOf(graph) == -1) {
            this.m_tGraphLst.push(graph);
            graph.m_layer = this;
        }
    }

    removeGraph(pGraph) {
        var posidx = this.m_tGraphLst.indexOf(pGraph);
        if (posidx >= 0) {
            this.m_tGraphLst.splice(posidx, 1);
        }
    }

    appendGraph2Lst(totalLst) {
        let len = this.m_tGraphLst.length;
        for (let i = 0; i < len; i++) {
            let temp = this.m_tGraphLst[i];
            totalLst.push(temp);
        }
    }

    generateGraph(toolKind, symbol, backColor) {
        var factory = GraphFactory.GraphFactory;
        var pNewGraph = factory.createGraphByType32(toolKind, symbol);
        if (pNewGraph) {
            this.addGraph(pNewGraph);
            // if (funcs.isBaseUnit(pNewGraph.getType())) {
            //     let lineInfo = pNewGraph.getLineDef();
            //     lineInfo.color.clone(backColor.invert());
            // }
        }
        return pNewGraph;
    }

    pickGraph(tPoint, mapViewInfo, matchLst, picktype) {
        if (this.lock) {
            return;
        }
        let count = this.m_tGraphLst.length;
        for (let i = count - 1; i >= 0; i--) {
            var graph = this.m_tGraphLst[i];
            if (graph.getUseful() == 0
                || graph.getFinish() == 0
                || !this.chkCanPickByType(graph, picktype)) {
                continue;
            }
            this.chkGraphCanBeSelect(graph, tPoint, mapViewInfo, matchLst);
        }
        return;
    }

    chkPreSelectGraph(destGraph, tPoint, mapViewInfo, matchLst) {
        if (destGraph.getModifing() || funcs.group(destGraph.getType()) == global.dimGroup) {
            return;
        }
        var scaling = mapViewInfo.getScaling();
        var mapscale = mapViewInfo.getMapScale();
        if (destGraph.preCheckInScope(tPoint, scaling)) {
            if (destGraph.m_graphType == LGXEnums.LGXGraphType.LineGraph_type) {
                //前面即使选中的是线，也需要再次精确判断
                let dis = destGraph.distance(tPoint, scaling, mapscale);
                if (dis < 0) {
                    return;
                }
            }
            let dis = 0;
            let selDstGraph = destGraph;
            let sup = destGraph.getContainer();
            if (sup) {
                if (destGraph.m_graphType == LGXEnums.LGXGraphType.TextGraph_type && destGraph.isTitle()) {
                    selDstGraph = sup;
                }
                else if (destGraph.m_graphType == LGXEnums.LGXGraphType.RectGraph_type) {
                    if (destGraph.getSymbolEdgeFlag() || destGraph.getTitleZoneFlag()) {
                        selDstGraph = sup;
                    }
                }
            }
            let t = { dst: selDstGraph, dis };
            let flag = false;
            matchLst.forEach(p => {
                if (p.dst == selDstGraph) {
                    flag = true;
                    return;
                }
            });
            if (!flag) {
                matchLst.push(t);
            }
        }

        return;
    }
    chkGraphCanBeSelect(destGraph, tPoint, mapViewInfo, matchLst) {
        if (destGraph.getModifing()) {
            return;
        }

        if (mapViewInfo.editMode == "xmind"
            && destGraph.m_graphType == LGXEnums.LGXGraphType.LineGraph_type) {
            return;
        }

        var scaling = mapViewInfo.getScaling();
        var mapscale = mapViewInfo.getMapScale();
        var dis = destGraph.distance(tPoint, scaling, mapscale);
        if (dis >= 0) {
            let selDstGraph = destGraph;
            let sup = destGraph.getContainer();
            if (sup) {
                if (destGraph.m_graphType == LGXEnums.LGXGraphType.TextGraph_type && destGraph.isTitle()) {
                    selDstGraph = sup;
                }
                else if (destGraph.m_graphType == LGXEnums.LGXGraphType.RectGraph_type) {
                    if (destGraph.getSymbolEdgeFlag() || destGraph.getTitleZoneFlag()) {
                        selDstGraph = sup;
                    }
                }
            }
            let areaSquare = destGraph.getZone().area();
            // if (destGraph.m_graphType == LGXEnums.LGXGraphType.LineGraph_type) 
            {
                areaSquare = dis;
            }
            let t = { dst: selDstGraph, dis: areaSquare };
            let flag = false;
            matchLst.forEach(p => {
                if (p.dst == selDstGraph) {
                    flag = true;
                    return;
                }
            });
            if (!flag) {
                matchLst.push(t);
            }
        }
        return;
    }

    display(map, mapInfo,refreshRect) {
        let count = 0;
        let hideCount = 0;
        let tt = new absgraph.LineUnitCounter();
        tt.lineUnitCount = 0;

        map.save();
        let mapscale = mapInfo.getMapScale();
        for (var idx in this.m_tGraphLst) {
            var graph = this.m_tGraphLst[idx]; 
            if (graph.getUseful() == 1) {
                if (graph.m_graphType == LGXEnums.LGXGraphType.TextGraph_type){
                    graph.calScopeUseMap(map,mapscale);
                }
                if (//funcs.group(graph.getType()) == global.dimGroup || 
                    funcs.chkRectInRect(graph.getZone(), refreshRect)) {
                    graph.display(map, mapInfo, false);
                    count++;
                }
                else {
                    hideCount++;
                }
            }
        }
        map.restore();
        // this.disTestCode(map,mapInfo);
        console.log("dis count:"+count);

        //被选中的后绘制，显示在前端
        //----这种方式会导致后绘制的图形被前面选中图形的填充模式影响，原因暂未找到，先屏蔽
        // let haveBeenSelectedGraphList = [];
        // for (var idx in this.m_tGraphLst) {
        //     var graph = this.m_tGraphLst[idx];
        //     if (graph.getUseful() == 1) {
        //         if (graph.getSelect() == 0) 
        //         {
        //             graph.display(map, mapInfo);
        //         }
        //         else 
        //         {
        //             haveBeenSelectedGraphList.push(graph);
        //         }
        //     }
        // }

        // for (var idx in haveBeenSelectedGraphList) {
        //     var graph = haveBeenSelectedGraphList[idx];
        //     graph.display(map, mapInfo);
        // }
    }

    disTestInfo(map, mapInfo) {
        let x = 300;
        let y = 200;
        var graphCnt = { x, y };
        var pt = CoordTRFUtil.world2Screen(graphCnt, mapInfo);

        map.beginPath();
        map.moveTo(0, 0);
        map.lineTo(pt.x, pt.y);
        map.stroke();
        map.closePath();
        map.restore();
    }

    chkInSelRect(rectRegion, tSelect) {
        if (!this.visible || this.lock) {
            return;
        }
        for (var idx in this.m_tGraphLst) {
            var pCntGraph = this.m_tGraphLst[idx];
            if (pCntGraph.getUseful() != 1) {
                continue;
            }

            if (pCntGraph.m_layer && (!pCntGraph.m_layer.visible || pCntGraph.m_layer.lock)) {
                continue;
            }
            let inRegion = pCntGraph.judgeInRect(rectRegion);
            if (inRegion != 0) {
                tSelect.push(pCntGraph);
            }
        }
    }

    getGraphIntersectSelRect(rectRegion, tSelect) {
        if (!this.visible || this.lock) {
            return;
        }
        for (var idx in this.m_tGraphLst) {
            var pCntGraph = this.m_tGraphLst[idx];
            if (pCntGraph.getUseful() != 1) {
                continue;
            }

            if (pCntGraph.m_layer && (!pCntGraph.m_layer.visible || pCntGraph.m_layer.lock)) {
                continue;
            }
            let inRegion = pCntGraph.chkIntersectRect(rectRegion);
            if (inRegion != 0) {
                tSelect.push(pCntGraph);
            }
        }
    }

    findGraph(gid) {
        var pDstGraph = null;
        for (var idx in this.m_tGraphLst) {
            var graph = this.m_tGraphLst[idx];
            if (graph.m_gid == gid) {
                pDstGraph = graph;
                break;
            }
        }
        return pDstGraph;
    }

    findGraphByRID(rid) {
        var pDstGraph = null;
        for (var idx in this.m_tGraphLst) {
            var graph = this.m_tGraphLst[idx];
            if (graph.m_rid == rid) {
                pDstGraph = graph;
                break;
            }
        }
        return pDstGraph;
    }

    getInlayerIdx(graph) {
        let idx = this.m_tGraphLst.indexOf(graph)
        if (idx == -1) {
            idx = 0;
        }
        return idx;
    }

    moveGraphUpward2DstIdx(dstGraph, dstIdx) {
        let lenth = this.m_tGraphLst.length;
        let curentIdx = this.m_tGraphLst.indexOf(dstGraph);
        let graph = this.m_tGraphLst[dstIdx];
        this.m_tGraphLst[dstIdx] = dstGraph;
        this.m_tGraphLst[curentIdx] = graph;
    }

    moveGraphToTop(dstGraph) {
        let lenth = this.m_tGraphLst.length;
        let curentIdx = this.m_tGraphLst.indexOf(dstGraph);

        let lowLayGraphLst = [];
        for (let i = 0; i < curentIdx; i++) {
            let p = this.m_tGraphLst[i];
            lowLayGraphLst.push(p);
        }

        let upLayGraphLst = [];
        for (let i = curentIdx + 1; i < lenth; i++) {
            let p = this.m_tGraphLst[i];
            upLayGraphLst.push(p);
        }

        this.m_tGraphLst.length = 0;
        for (let i = 0; i < lowLayGraphLst.length; i++) {
            let p = lowLayGraphLst[i];
            this.m_tGraphLst.push(p);
        }

        for (let i = 0; i < upLayGraphLst.length; i++) {
            let p = upLayGraphLst[i];
            this.m_tGraphLst.push(p);
        }
        this.m_tGraphLst.push(dstGraph);
    }

    moveGraphToBottom(dstGraph) {
        let lenth = this.m_tGraphLst.length;
        let curentIdx = this.m_tGraphLst.indexOf(dstGraph);

        let lowLayGraphLst = [];
        for (let i = 0; i < curentIdx; i++) {
            let p = this.m_tGraphLst[i];
            lowLayGraphLst.push(p);
        }

        let upLayGraphLst = [];
        for (let i = curentIdx + 1; i < lenth; i++) {
            let p = this.m_tGraphLst[i];
            upLayGraphLst.push(p);
        }

        this.m_tGraphLst.length = 0;
        this.m_tGraphLst.push(dstGraph);
        for (let i = 0; i < lowLayGraphLst.length; i++) {
            let p = lowLayGraphLst[i];
            this.m_tGraphLst.push(p);
        }

        for (let i = 0; i < upLayGraphLst.length; i++) {
            let p = upLayGraphLst[i];
            this.m_tGraphLst.push(p);
        }
    }

    clearData() {
        this.m_tGraphLst.length = 0;
    }

    chkCanPickByType(graph, picktype) {
        if (!picktype) {
            return true;
        }
        let flag = true;
        switch (picktype) {
            case "dim":
                flag = funcs.isBaseUnit(graph.getType());
                if (graph.m_graphType == LGXEnums.LGXGraphType.TextGraph_type
                    || graph.m_graphType == LGXEnums.LGXGraphType.TextGraph_type) {
                    flag = false;
                }
                break;

            case "blockGraph":
                flag = (graph.getSymbol() != null);
                break;

            case "linegraph":
                flag = (graph.m_graphType == LGXEnums.LGXGraphType.LineGraph_type);
                break;

            default:
                break;
        }
        return flag;
    }

    disTestCode(map, mapInfo) {
        let ptlist = [
            {
                "x": 0.00020195108684893106,
                "y": -0.0005302096217301591
            },
            {
                "x": 0.0002012830472962674,
                "y": -0.0005305243312932685
            },
            {
                "x": 0.0002005957743289115,
                "y": -0.0005307798163529233
            },
            {
                "x": 0.0001998987783524314,
                "y": -0.0005309907222310287
            },
            {
                "x": 0.00019920156977240065,
                "y": -0.0005311716942494882
            },
            {
                "x": 0.00019851365899438078,
                "y": -0.0005313373777302106
            },
            {
                "x": 0.00019784455642395118,
                "y": -0.0005315024179950948
            },
            {
                "x": 0.00019720377246667625,
                "y": -0.0005316814603660483
            },
            {
                "x": 0.00019659866581801086,
                "y": -0.0005318870757788918
            },
            {
                "x": 0.00019602798833293775,
                "y": -0.0005321235376251073
            },
            {
                "x": 0.00019548834015632892,
                "y": -0.0005323930449100946
            },
            {
                "x": 0.00019472161781351898,
                "y": -0.0005328493953307561
            },
            {
                "x": 0.00019379092689625425,
                "y": -0.0005336104311536603
            },
            {
                "x": 0.000193136543970635,
                "y": -0.0005343132281055584
            },
            {
                "x": 0.00019271514991434378,
                "y": -0.000534827061466228
            },
            {
                "x": 0.00019232183754436607,
                "y": -0.0005353885792815365
            },
            {
                "x": 0.00019197405836934164,
                "y": -0.0005359992265349567
            },
            {
                "x": 0.00019168926389790826,
                "y": -0.000536660448209964
            },
            {
                "x": 0.00019148490563870453,
                "y": -0.0005373736892900304
            },
            {
                "x": 0.00019137843510036939,
                "y": -0.0005381403947586312
            },
            {
                "x": 0.000191387303791541,
                "y": -0.0005389620095992396
            },
            {
                "x": 0.000191528963220858,
                "y": -0.0005398399787953284
            },
            {
                "x": 0.00019181344013825488,
                "y": -0.0005407732636524212
            },
            {
                "x": 0.00019222106225885003,
                "y": -0.0005417508907642215
            },
            {
                "x": 0.00019272473253905827,
                "y": -0.0005427594030464823
            },
            {
                "x": 0.0001932973539352939,
                "y": -0.0005437853434149564
            },
            {
                "x": 0.00019391182940397118,
                "y": -0.0005448152547853956
            },
            {
                "x": 0.00019454106190150007,
                "y": -0.0005458356800735503
            },
            {
                "x": 0.00019515795438431024,
                "y": -0.0005468331621951816
            },
            {
                "x": 0.0001957354098088015,
                "y": -0.0005477942440660343
            },
            {
                "x": 0.0001962518936571334,
                "y": -0.000548710448719987
            },
            {
                "x": 0.00019670812151443258,
                "y": -0.0005495932196634255
            },
            {
                "x": 0.000197110371491564,
                "y": -0.0005504589805208571
            },
            {
                "x": 0.0001974649216993941,
                "y": -0.0005513241549167921
            },
            {
                "x": 0.0001977780502487899,
                "y": -0.000552205166475739
            },
            {
                "x": 0.00019805603525061704,
                "y": -0.0005531184388222062
            },
            {
                "x": 0.00019830515481574157,
                "y": -0.0005540803955807038
            },
            {
                "x": 0.000198531687055031,
                "y": -0.0005551074603757402
            },
            {
                "x": 0.00019873892717341935,
                "y": -0.0005562084491980283
            },
            {
                "x": 0.00019891823875212153,
                "y": -0.0005573617475031085
            },
            {
                "x": 0.00019905800246641954,
                "y": -0.0005585381331127203
            },
            {
                "x": 0.0001991465989915967,
                "y": -0.0005597083838486041
            },
            {
                "x": 0.00019917240900293586,
                "y": -0.000560843277532505
            },
            {
                "x": 0.0001991238131757201,
                "y": -0.0005619135919861624
            },
            {
                "x": 0.00019898919218523192,
                "y": -0.0005628901050313188
            },
            {
                "x": 0.00019875692670675448,
                "y": -0.0005637435944897166
            },
            {
                "x": 0.00019841994677127073,
                "y": -0.0005644518288762133
            },
            {
                "x": 0.00019798937983256498,
                "y": -0.0005650205394781274
            },
            {
                "x": 0.00019748090270012118,
                "y": -0.0005654624482758961
            },
            {
                "x": 0.00019691019218342313,
                "y": -0.0005657902772499533
            },
            {
                "x": 0.00019629292509195588,
                "y": -0.0005660167483807352
            },
            {
                "x": 0.00019564477823520276,
                "y": -0.0005661545836486754
            },
            {
                "x": 0.00019498142842264778,
                "y": -0.0005662165050342128
            },
            {
                "x": 0.00019431855246377776,
                "y": -0.0005662152345177792
            },
            {
                "x": 0.00019366934033710026,
                "y": -0.0005661614223963141
            },
            {
                "x": 0.00019303703469723994,
                "y": -0.0005660574322327703
            },
            {
                "x": 0.0001924223913678472,
                "y": -0.0005659035559066009
            },
            {
                "x": 0.00019182616617257177,
                "y": -0.0005657000852972625
            },
            {
                "x": 0.00019124911493506269,
                "y": -0.0005654473122842081
            },
            {
                "x": 0.00019069199347897088,
                "y": -0.0005651455287468943
            },
            {
                "x": 0.00019015555762794614,
                "y": -0.0005647950265647746
            },
            {
                "x": 0.00018964056320563803,
                "y": -0.0005643960976173043
            },
            {
                "x": 0.0001891471463924307,
                "y": -0.0005639506868666526
            },
            {
                "x": 0.0001886729647956413,
                "y": -0.0005634673516058493
            },
            {
                "x": 0.00018821505637932098,
                "y": -0.0005629563022106388
            },
            {
                "x": 0.0001877704591075213,
                "y": -0.0005624277490567639
            },
            {
                "x": 0.00018733621094429046,
                "y": -0.0005618919025199638
            },
            {
                "x": 0.00018690934985368112,
                "y": -0.0005613589729759887
            },
            {
                "x": 0.00018648691379975055,
                "y": -0.0005608391708005873
            },
            {
                "x": 0.00018587402525542103,
                "y": -0.000560116375457356
            },
            {
                "x": 0.00018522625160100864,
                "y": -0.0005594413273600897
            },
            {
                "x": 0.00018481497107774008,
                "y": -0.000559030289318981
            },
            {
                "x": 0.00018441516664205034,
                "y": -0.0005586399945381429
            },
            {
                "x": 0.00018403116333487002,
                "y": -0.0005582661747309735
            },
            {
                "x": 0.000183667286197134,
                "y": -0.0005579045616108823
            },
            {
                "x": 0.00018332786026977997,
                "y": -0.0005575508868912737
            },
            {
                "x": 0.0001830172105937372,
                "y": -0.0005572008822855481
            },
            {
                "x": 0.00018273870834668274,
                "y": -0.0005568504868556375
            },
            {
                "x": 0.00018249190925325237,
                "y": -0.0005564964690575533
            },
            {
                "x": 0.00018227541517482342,
                "y": -0.0005561358046958346
            },
            {
                "x": 0.0001820878279727719,
                "y": -0.0005557654695750171
            },
            {
                "x": 0.00018192774950847562,
                "y": -0.0005553824394996421
            },
            {
                "x": 0.00018179378164331079,
                "y": -0.0005549836902742423
            },
            {
                "x": 0.00018168452623865456,
                "y": -0.00055456619770336
            },
            {
                "x": 0.0001815985851558837,
                "y": -0.0005541269375915294
            },
            {
                "x": 0.00018153452211986214,
                "y": -0.0005536635505798245
            },
            {
                "x": 0.00018149074830940085,
                "y": -0.0005531763366554621
            },
            {
                "x": 0.00018146563676679818,
                "y": -0.0005526662606421993
            },
            {
                "x": 0.00018145756053435216,
                "y": -0.0005521342873637854
            },
            {
                "x": 0.00018146489265436088,
                "y": -0.0005515813816439746
            },
            {
                "x": 0.00018148600616912258,
                "y": -0.0005510085083065202
            },
            {
                "x": 0.00018151927412093474,
                "y": -0.0005504166321751817
            },
            {
                "x": 0.00018156306955209616,
                "y": -0.0005498067180737039
            },
            {
                "x": 0.00018161563217725335,
                "y": -0.0005491807866367117
            },
            {
                "x": 0.00018167466840044252,
                "y": -0.0005485450817422894
            },
            {
                "x": 0.00018173775129804606,
                "y": -0.0005479069030794201
            },
            {
                "x": 0.00018180245394645416,
                "y": -0.0005472735503370241
            },
            {
                "x": 0.0001818663494220492,
                "y": -0.0005466523232040718
            },
            {
                "x": 0.00018192701080121346,
                "y": -0.0005460505213695525
            },
            {
                "x": 0.00018198201116033515,
                "y": -0.0005454754445223915
            },
            {
                "x": 0.00018202892357579824,
                "y": -0.0005449343923515533
            },
            {
                "x": 0.00018208447246354986,
                "y": -0.0005441756693134974
            },
            {
                "x": 0.00018211562528030307,
                "y": -0.0005432848508292591
            },
            {
                "x": 0.00018210523477524425,
                "y": -0.0005424139154667393
            },
            {
                "x": 0.00018206572561125676,
                "y": -0.0005417049990259863
            },
            {
                "x": 0.00018202892357579807,
                "y": -0.0005412023327570528
            },
            {
                "x": 0.00018198104813830674,
                "y": -0.0005406631254025009
            },
            {
                "x": 0.00018191930662498596,
                "y": -0.0005401009622693432
            },
            {
                "x": 0.00018184034782728055,
                "y": -0.0005395342119442624
            },
            {
                "x": 0.00018174082053663512,
                "y": -0.0005389812430139327
            },
            {
                "x": 0.00018154922062387183,
                "y": -0.0005381728890520926
            },
            {
                "x": 0.00018118947941118095,
                "y": -0.0005373765679748387
            },
            {
                "x": 0.00018070717178357855,
                "y": -0.0005369647518387582
            },
            {
                "x": 0.00018009914158850015,
                "y": -0.0005368520039447262
            },
            {
                "x": 0.00017952456962636954,
                "y": -0.0005368928657840626
            },
            {
                "x": 0.00017915008408180076,
                "y": -0.0005369327837528166
            },
            {
                "x": 0.0001787636783244405,
                "y": -0.0005369688982800323
            },
            {
                "x": 0.00017836958640810003,
                "y": -0.0005369829714040961
            },
            {
                "x": 0.0001779720393837279,
                "y": -0.0005369600860429107
            },
            {
                "x": 0.00017757525629076793,
                "y": -0.0005368986086324511
            },
            {
                "x": 0.00017718345316579035,
                "y": -0.0005368002264882059
            },
            {
                "x": 0.0001768008460453648,
                "y": -0.0005366666269256661
            },
            {
                "x": 0.00017643165096606125,
                "y": -0.0005364994972603217
            },
            {
                "x": 0.00017608008396444887,
                "y": -0.0005363005248076636
            },
            {
                "x": 0.00017575036107709757,
                "y": -0.0005360713968831809
            },
            {
                "x": 0.00017544669834057734,
                "y": -0.0005358138008023655
            },
            {
                "x": 0.00017517328716788234,
                "y": -0.0005355273407862873
            },
            {
                "x": 0.00017493422047770477,
                "y": -0.0005352032886783235
            },
            {
                "x": 0.00017473356656516262,
                "y": -0.0005348308332274346
            },
            {
                "x": 0.00017457539372537246,
                "y": -0.0005343991631825786
            },
            {
                "x": 0.00017446377025345217,
                "y": -0.000533897467292716
            },
            {
                "x": 0.00017440276444451852,
                "y": -0.0005333149343068029
            },
            {
                "x": 0.00017439644459368907,
                "y": -0.0005326407529738012
            },
            {
                "x": 0.00017444887899608098,
                "y": -0.0005318641120426685
            },
            {
                "x": 0.00017456086866861377,
                "y": -0.0005309793869782906
            },
            {
                "x": 0.00017472014551541591,
                "y": -0.000530001700109277
            },
            {
                "x": 0.00017491117416241773,
                "y": -0.0005289513604801615
            },
            {
                "x": 0.00017511841923555186,
                "y": -0.0005278486771354792
            },
            {
                "x": 0.00017532634536074354,
                "y": -0.000526713959119771
            },
            {
                "x": 0.00017551941716392955,
                "y": -0.0005255675154775698
            },
            {
                "x": 0.0001756820992710379,
                "y": -0.0005244296552534083
            },
            {
                "x": 0.0001757988563079995,
                "y": -0.0005233206874918244
            },
            {
                "x": 0.0001758564687179832,
                "y": -0.0005222559866127831
            },
            {
                "x": 0.0001758509802131112,
                "y": -0.0005212311885379789
            },
            {
                "x": 0.00017578075032274382,
                "y": -0.0005202369945645301
            },
            {
                "x": 0.00017564413857624157,
                "y": -0.0005192641059895573
            },
            {
                "x": 0.00017543950450296469,
                "y": -0.0005183032241101847
            },
            {
                "x": 0.00017516520763227365,
                "y": -0.0005173450502235315
            },
            {
                "x": 0.00017481960749352857,
                "y": -0.0005163802856267189
            },
            {
                "x": 0.00017440106361609056,
                "y": -0.000515399631616869
            },
            {
                "x": 0.00017391047671232973,
                "y": -0.0005143969854510179
            },
            {
                "x": 0.00017335891222666132,
                "y": -0.0005133790282258627
            },
            {
                "x": 0.00017275997678650902,
                "y": -0.0005123556369980195
            },
            {
                "x": 0.0001721272770192992,
                "y": -0.000511336688824097
            },
            {
                "x": 0.00017147441955245505,
                "y": -0.0005103320607607131
            },
            {
                "x": 0.00017081501101340427,
                "y": -0.0005093516298644802
            },
            {
                "x": 0.0001701626580295662,
                "y": -0.0005084052731920079
            },
            {
                "x": 0.00016953096722837106,
                "y": -0.0005075028677999108
            },
            {
                "x": 0.00016893110029638517,
                "y": -0.0005066524322654427
            },
            {
                "x": 0.00016836443915668625,
                "y": -0.000505854551248362
            },
            {
                "x": 0.00016782992079152512,
                "y": -0.0005051079509290806
            },
            {
                "x": 0.0001673264821831331,
                "y": -0.0005044113574880082
            },
            {
                "x": 0.00016685306031372633,
                "y": -0.0005037634971055301
            },
            {
                "x": 0.00016640859216555468,
                "y": -0.000503163095962067
            },
            {
                "x": 0.00016599201472084488,
                "y": -0.0005026088802380198
            },
            {
                "x": 0.00016540168038329083,
                "y": -0.0005018374629225887
            },
            {
                "x": 0.000164714609564676,
                "y": -0.0005009821091979357
            },
            {
                "x": 0.0001640486427612154,
                "y": -0.0005002069873883668
            },
            {
                "x": 0.00016333913158602975,
                "y": -0.0004994381586259766
            },
            {
                "x": 0.00016271350877326523,
                "y": -0.0004987981624336043
            },
            {
                "x": 0.00016226022793754116,
                "y": -0.0004983466674076722
            },
            {
                "x": 0.0001617646975507297,
                "y": -0.0004978770713512264
            },
            {
                "x": 0.000161224500598705,
                "y": -0.0004974026016285766
            },
            {
                "x": 0.0001606372200673393,
                "y": -0.0004969364856040263
            },
            {
                "x": 0.00016000043894250548,
                "y": -0.0004964919506418834
            },
            {
                "x": 0.00015931174021007578,
                "y": -0.0004960822241064529
            },
            {
                "x": 0.000158568706855923,
                "y": -0.0004957205333620417
            },
            {
                "x": 0.00015776892186591913,
                "y": -0.0004954201057729566
            },
            {
                "x": 0.0001569125660131425,
                "y": -0.0004951894573426931
            },
            {
                "x": 0.00015601021121949328,
                "y": -0.0004950182586315129
            },
            {
                "x": 0.000155075027194076,
                "y": -0.0004948914688388669
            },
            {
                "x": 0.00015412018364599603,
                "y": -0.0004947940471642065
            },
            {
                "x": 0.00015315885028434846,
                "y": -0.000494710952806982
            },
            {
                "x": 0.00015220419681826998,
                "y": -0.000494627144966647
            },
            {
                "x": 0.00015126939295683416,
                "y": -0.0004945275828426511
            },
            {
                "x": 0.0001503676084091567,
                "y": -0.0004943972256344452
            },
            {
                "x": 0.0001495089988986556,
                "y": -0.0004942231459649424
            },
            {
                "x": 0.00014869166420599937,
                "y": -0.0004940008701508927
            },
            {
                "x": 0.00014791069012616895,
                "y": -0.0004937280379325068
            },
            {
                "x": 0.0001471611624541461,
                "y": -0.000493402289049997
            },
            {
                "x": 0.00014643816698491183,
                "y": -0.0004930212632435724
            },
            {
                "x": 0.00014573678951344753,
                "y": -0.0004925826002534449
            },
            {
                "x": 0.00014505211583473425,
                "y": -0.0004920839398198264
            },
            {
                "x": 0.00014437923174375356,
                "y": -0.000491522921682926
            },
            {
                "x": 0.0001437184529928168,
                "y": -0.0004909004894962289
            },
            {
                "x": 0.000143091015163556,
                "y": -0.0004902308025663139
            },
            {
                "x": 0.00014252338379493437,
                "y": -0.0004895313241130304
            },
            {
                "x": 0.0001420420244259137,
                "y": -0.000488819517356232
            },
            {
                "x": 0.000141673402595457,
                "y": -0.00048811284551576804
            },
            {
                "x": 0.0001414439838425266,
                "y": -0.00048742877181148976
            },
            {
                "x": 0.00014138023370608517,
                "y": -0.0004867847594632484
            },
            {
                "x": 0.00014150861772509516,
                "y": -0.00048619827169089637
            },
            {
                "x": 0.00014184520548509726,
                "y": -0.00048568230899152825
            },
            {
                "x": 0.00014236448275794464,
                "y": -0.0004852320209712218
            },
            {
                "x": 0.00014303053936206886,
                "y": -0.00048483809451329673
            },
            {
                "x": 0.00014380746511590125,
                "y": -0.0004844912165010745
            },
            {
                "x": 0.00014465934983787197,
                "y": -0.00048418207381787607
            },
            {
                "x": 0.00014555028334641386,
                "y": -0.00048390135334702207
            },
            {
                "x": 0.00014644435545995788,
                "y": -0.00048363974197183397
            },
            {
                "x": 0.0001473056559969351,
                "y": -0.0004833879265756338
            },
            {
                "x": 0.00014810665685104622,
                "y": -0.0004831370808077873
            },
            {
                "x": 0.00014885335821707244,
                "y": -0.00048288032538184173
            },
            {
                "x": 0.00014956014236506323,
                "y": -0.00048261126777739317
            },
            {
                "x": 0.00015024139156507,
                "y": -0.00048232351547403607
            },
            {
                "x": 0.0001509114880871423,
                "y": -0.00048201067595136465
            },
            {
                "x": 0.00015158481420133024,
                "y": -0.00048166635668897193
            },
            {
                "x": 0.0001522757521776842,
                "y": -0.00048128416516645257
            },
            {
                "x": 0.00015299868428625676,
                "y": -0.00048085770886340277
            },
            {
                "x": 0.00015376511949609985,
                "y": -0.000480388531557884
            },
            {
                "x": 0.0001545750735723173,
                "y": -0.00047990992222183345
            },
            {
                "x": 0.0001554256889790049,
                "y": -0.00047946310612565895
            },
            {
                "x": 0.00015631410818026727,
                "y": -0.0004790893085397671
            },
            {
                "x": 0.00015723747364020777,
                "y": -0.0004788297547345631
            },
            {
                "x": 0.00015819292782292898,
                "y": -0.0004787256699804548
            },
            {
                "x": 0.00015917761319253333,
                "y": -0.00047881827954784835
            },
            {
                "x": 0.00016018867221312373,
                "y": -0.00047914880870715033
            },
            {
                "x": 0.00016122244453015833,
                "y": -0.0004797435237565645
            },
            {
                "x": 0.00016227205851451738,
                "y": -0.0004805688551054776
            },
            {
                "x": 0.00016332983971843642,
                "y": -0.0004815762741910769
            },
            {
                "x": 0.00016438811369415103,
                "y": -0.00048271725245054633
            },
            {
                "x": 0.00016543920599389745,
                "y": -0.0004839432613210711
            },
            {
                "x": 0.00016647544216991008,
                "y": -0.00048520577223983724
            },
            {
                "x": 0.0001674891477744248,
                "y": -0.00048645625664402913
            },
            {
                "x": 0.00016847264835967785,
                "y": -0.0004876461859708338
            },
            {
                "x": 0.00016942269826817342,
                "y": -0.0004887378552202628
            },
            {
                "x": 0.0001703537670034782,
                "y": -0.0004897368536436478
            },
            {
                "x": 0.0001712847528594326,
                "y": -0.0004906595940551465
            },
            {
                "x": 0.0001722345541298725,
                "y": -0.0004915224892689192
            },
            {
                "x": 0.00017322206910863608,
                "y": -0.0004923419520991227
            },
            {
                "x": 0.00017426619608956032,
                "y": -0.0004931343953599168
            },
            {
                "x": 0.00017538583336648396,
                "y": -0.000493916231865462
            },
            {
                "x": 0.00017659987923324233,
                "y": -0.0004947038744299156
            },
            {
                "x": 0.00017791963005534282,
                "y": -0.0004955097560069888
            },
            {
                "x": 0.00017932597448496146,
                "y": -0.0004963303901086053
            },
            {
                "x": 0.00018079219924594522,
                "y": -0.0004971583103862432
            },
            {
                "x": 0.0001822915910621409,
                "y": -0.0004979860504913777
            },
            {
                "x": 0.00018379743665739034,
                "y": -0.0004988061440754839
            },
            {
                "x": 0.00018528302275554133,
                "y": -0.0004996111247900421
            },
            {
                "x": 0.00018672163608044669,
                "y": -0.0005003935262865285
            },
            {
                "x": 0.00018808656335594405,
                "y": -0.0005011458822164171
            },
            {
                "x": 0.00018935644738396468,
                "y": -0.0005018619802318064
            },
            {
                "x": 0.00019053135527876522,
                "y": -0.0005025406239872763
            },
            {
                "x": 0.00019161671023268362,
                "y": -0.000503181871138028
            },
            {
                "x": 0.00019261793543806025,
                "y": -0.000503785779339262
            },
            {
                "x": 0.0001935404540872388,
                "y": -0.00050435240624618
            },
            {
                "x": 0.00019438968937255099,
                "y": -0.0005048818095139813
            },
            {
                "x": 0.0001951710644863384,
                "y": -0.0005053740467978656
            },
            {
                "x": 0.00019589000262095697,
                "y": -0.0005058291757530443
            },
            {
                "x": 0.00019655342510309544,
                "y": -0.0005062487458630359
            },
            {
                "x": 0.00019717424579688948,
                "y": -0.000506640273924655
            },
            {
                "x": 0.00019776687670088484,
                "y": -0.0005070127685630696
            },
            {
                "x": 0.0001983457298135475,
                "y": -0.0005073752384033999
            },
            {
                "x": 0.00019892521713345016,
                "y": -0.0005077366920708315
            },
            {
                "x": 0.0001995197506590606,
                "y": -0.0005081061381904851
            },
            {
                "x": 0.0002001437423889206,
                "y": -0.0005084925853875281
            },
            {
                "x": 0.0002008116043215247,
                "y": -0.0005089050422870978
            },
            {
                "x": 0.00020153178339424812,
                "y": -0.0005093511848383974
            },
            {
                "x": 0.0002022888662998962,
                "y": -0.0005098333582868431
            },
            {
                "x": 0.00020306147467012562,
                "y": -0.0005103525752019032
            },
            {
                "x": 0.0002038282301365959,
                "y": -0.0005109098481530415
            },
            {
                "x": 0.00020456775433096586,
                "y": -0.0005115061897097253
            },
            {
                "x": 0.0002052586688848946,
                "y": -0.0005121426124414216
            },
            {
                "x": 0.00020587959543004152,
                "y": -0.0005128201289175983
            },
            {
                "x": 0.00020640915559806523,
                "y": -0.0005135397517077202
            },
            {
                "x": 0.0002068314676332595,
                "y": -0.0005143003826603825
            },
            {
                "x": 0.00020715263623045677,
                "y": -0.000515092480740691
            },
            {
                "x": 0.00020738426269712357,
                "y": -0.0005159043941928761
            },
            {
                "x": 0.00020753794834072685,
                "y": -0.0005167244712611712
            },
            {
                "x": 0.00020762529446873346,
                "y": -0.0005175410601898088
            },
            {
                "x": 0.0002076579023886101,
                "y": -0.0005183425092230223
            },
            {
                "x": 0.0002076473734078236,
                "y": -0.0005191171666050407
            },
            {
                "x": 0.0002076053088338405,
                "y": -0.0005198533805801012
            },
            {
                "x": 0.00020754091923515732,
                "y": -0.0005205431926284532
            },
            {
                "x": 0.00020745385222438668,
                "y": -0.000521193417174454
            },
            {
                "x": 0.00020734136467517078,
                "y": -0.0005218145618784735
            },
            {
                "x": 0.00020720071346115156,
                "y": -0.0005224171344008861
            },
            {
                "x": 0.0002070291554559718,
                "y": -0.0005230116424020643
            },
            {
                "x": 0.00020682394753327284,
                "y": -0.0005236085935423838
            },
            {
                "x": 0.00020658234656669702,
                "y": -0.0005242184954822166
            },
            {
                "x": 0.00020630160942988697,
                "y": -0.0005248518558819377
            },
            {
                "x": 0.00020597952570651872,
                "y": -0.0005255148794321186
            },
            {
                "x": 0.0002056160158204025,
                "y": -0.0005261965589441195
            },
            {
                "x": 0.00020521153290538454,
                "y": -0.0005268815842595007
            },
            {
                "x": 0.00020476653009530847,
                "y": -0.0005275546452198216
            },
            {
                "x": 0.00020428146052402034,
                "y": -0.0005282004316666416
            },
            {
                "x": 0.00020375677732536445,
                "y": -0.0005288036334415206
            },
            {
                "x": 0.00020319293363318646,
                "y": -0.0005293489403860178
            },
            {
                "x": 0.00020259038258133095,
                "y": -0.0005298210423416909
            },
            {
                "x": 0.00020195108684893106,
                "y": -0.0005302096217301591
            }
        ];

        map.save();
        map.scale(2, 2);
        map.save();
        map.scale(100, 100);
        map.beginPath();
        let pt = ptlist[0];
        map.moveTo(pt.x, pt.y);
        for (let i = 1; i < ptlist.length; i++) {
            pt = ptlist[i];
            map.lineTo(pt.x, pt.y);
        }
        let zone = funcs.calPtListZone(ptlist);
        let wid = zone.width();
        let hgt = zone.height();
        map.strokeStyle = "#ffff00ff";
        map.stroke();
        map.restore();
        map.restore();
    }

}

export default { Layer }